import axios from 'axios'
import qs from 'qs'

const APP_KEY = '308b4c2d7797a85b';

const axiosPost = options => {
	axios.post(
		options.url,
		qs.stringify({
			appkey: APP_KEY,
            ...options.body
		})
	).then(res => {
		// console.log('2222')
		options.success(res)
		  console.log(res.data.result)
	}).catch(err => {
		options.error(err)
	})
}

const getFLData = () => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/class',
			success:function(data){
				resolve(data)
				// console.log('1111')
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

const getJSData = (gjz,number) => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/search',
            body:{
                keyword: gjz,
                num:number
            },
			success:function(data){
				resolve(data)
				// console.log('1111')
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

const getFLJSData = (id,sta,number) => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/byclass',
            body:{
                classid: id,
                start:sta,
                num:number
            },
			success:function(data){
				resolve(data)
				// console.log('1111')
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

const getByIdData = (id) => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/byclass',
            body:{
                id: id,
            },
			success:function(data){
				resolve(data)
				// console.log('1111')
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

export{
    getFLData,
    getJSData,
    getFLJSData,
    getByIdData
}